﻿'use strict';

angular.module('ishaCrmApp')
    .controller('alertsCtrl', ['$scope', 'stateSvc', function ($scope, stateSvc) {

        $scope.messages = stateSvc.alertMessages;

        $scope.$onRootScope('EVENT:ALERTS-ADDED', function (event, alertMessages) {
            //console.log('EVENT:ALERTS-ADDED', alertMessages);
            $scope.messages = alertMessages;
            $scope.$apply();
        });

        $scope.$onRootScope('EVENT:ALERTS-REMOVED', function (event, alertMessages) {
            //console.log('EVENT:ALERTS-REMOVED', alertMessages);
            $scope.messages = alertMessages;
        });

        $scope.remove = function (messageToRemove) {
            stateSvc.alertRemove(messageToRemove);
        }

    }]);